package com.xuelang.pipeline.artifact.app.nexus3v1;

import com.xuelang.pipeline.artifact.app.nexus3v1.config.Nexus3v1RestFeignConfig;
import com.xuelang.pipeline.artifact.app.nexus3v1.fallback.RepositoryManagementServiceFallbackFactory;
import com.xuelang.pipeline.artifact.app.nexus3v1.request.*;
import com.xuelang.pipeline.artifact.app.nexus3v1.response.ListRepositoryResponse;
import com.xuelang.pipeline.artifact.app.nexus3v1.xo.ApiResponseXO;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;

import jakarta.validation.Valid;
import java.util.List;

/**
 * 封装NexusOSS 3.37.3-02以上仓库相关接口-对应Repository Management
 * 包含仓库列表、创建仓库（Maven、Docker、Npm、Raw）、删除仓库（Maven、Docker、Npm、Raw）、仓库详情
 *
 * @author xiwen.zxg
 * @since 2024/7/9
 */
@FeignClient(
        name = "repository-management-service",
        url = "${feign.rpc.nexus3V1RestService}",
        configuration = Nexus3v1RestFeignConfig.class,
        fallbackFactory = RepositoryManagementServiceFallbackFactory.class)
public interface RepositoryManagementService {
    
    /**
     * 查询仓库列表
     *
     * @return
     */
    @GetMapping(value = "/v1/repositories", produces = "application/json;charset=utf-8")
    ApiResponseXO<List<ListRepositoryResponse>> listRepository();

    /**
     * 删除任意格式的仓库
     *
     * @param repositoryName
     * @return
     */
    @DeleteMapping(value = "/v1/repositories/{repositoryName}", produces = "application/json;charset=utf-8")
    ApiResponseXO<Void> deleteRepositoryOfAnyFormat(@PathVariable("repositoryName") String repositoryName);

    /**
     * 创建Maven-group仓库
     *
     * @param request
     * @return
     */
    @PostMapping(value = "/v1/repositories/maven/group", produces = "application/json;charset=utf-8")
    ApiResponseXO<Void> createMavenGroupRepository(@RequestBody @Valid CreateMavenGroupRequest request);


    /**
     * 更新Maven-group仓库
     *
     * @param repositoryName
     * @param request
     * @return
     */
    @PutMapping(value = "/v1/repositories/maven/group/{repositoryName}", produces = "application/json;charset=utf-8")
    ApiResponseXO<Void> updateMavenGroupRepository(@PathVariable("repositoryName") String repositoryName, @RequestBody @Valid CreateMavenGroupRequest request);

    /**
     * 创建Maven-hosted仓库
     *
     * @param request
     * @return
     */
    @PostMapping(value = "/v1/repositories/maven/hosted", produces = "application/json;charset=utf-8")
    ApiResponseXO<Void> createMavenHostedRepository(@RequestBody @Valid CreateMavenHostedRequest request);

    /**
     * 创建Maven-proxy仓库
     *
     * @param request
     * @return
     */
    @PostMapping(value = "/v1/repositories/maven/proxy", produces = "application/json;charset=utf-8")
    ApiResponseXO<Void> createMavenProxyRepository(@RequestBody @Valid CreateMavenProxyRequest request);

    /**
     * 创建Npm-group仓库
     *
     * @param request
     * @return
     */
    @PostMapping(value = "/v1/repositories/npm/group", produces = "application/json;charset=utf-8")
    ApiResponseXO<Void> createNpmGroupRepository(@RequestBody @Valid CreateNpmGroupRequest request);

    /**
     * 更新Npm-group仓库
     *
     * @param repositoryName
     * @param request
     * @return
     */
    @PutMapping(value = "/v1/repositories/npm/group/{repositoryName}", produces = "application/json;charset=utf-8")
    ApiResponseXO<Void> updateNpmGroupRepository(@PathVariable("repositoryName") String repositoryName, @RequestBody @Valid CreateNpmGroupRequest request);

    /**
     * 创建Npm-hosted仓库
     *
     * @param request
     * @return
     */
    @PostMapping(value = "/v1/repositories/npm/hosted", produces = "application/json;charset=utf-8")
    ApiResponseXO<Void> createNpmHostedRepository(@RequestBody @Valid CreateNpmHostedRequest request);

    /**
     * 创建Npm-proxy仓库
     *
     * @param request
     * @return
     */
    @PostMapping(value = "/v1/repositories/npm/proxy", produces = "application/json;charset=utf-8")
    ApiResponseXO<Void> createNpmProxyRepository(@RequestBody @Valid CreateNpmProxyRequest request);

    /**
     * 创建Docker-group仓库
     *
     * @param request
     * @return
     */
    @PostMapping(value = "/v1/repositories/docker/group", produces = "application/json;charset=utf-8")
    ApiResponseXO<Void> createDockerGroupRepository(@RequestBody @Valid CreateDockerGroupRequest request);

    /**
     * 创建Docker-group仓库
     *
     * @param repositoryName
     * @param request
     * @return
     */
    @PutMapping(value = "/v1/repositories/docker/group/{repositoryName}", produces = "application/json;charset=utf-8")
    ApiResponseXO<Void> updateDockerGroupRepository(@PathVariable("repositoryName") String repositoryName, @RequestBody @Valid CreateDockerGroupRequest request);

    /**
     * 创建Docker-hosted仓库
     *
     * @param request
     * @return
     */
    @PostMapping(value = "/v1/repositories/docker/hosted", produces = "application/json;charset=utf-8")
    ApiResponseXO<Void> createDockerHostedRepository(@RequestBody @Valid CreateDockerHostedRequest request);

    /**
     * 创建Docker-proxy仓库
     *
     * @param request
     * @return
     */
    @PostMapping(value = "/v1/repositories/docker/proxy", produces = "application/json;charset=utf-8")
    ApiResponseXO<Void> createDockerProxyRepository(@RequestBody @Valid CreateDockerProxyRequest request);

    /**
     * 创建Raw-group仓库
     *
     * @param request
     * @return
     */
    @PostMapping(value = "/v1/repositories/raw/group", produces = "application/json;charset=utf-8")
    ApiResponseXO<Void> createRawGroupRepository(@RequestBody @Valid CreateRawGroupRequest request);

    /**
     * 更新Raw-group仓库
     *
     * @param request
     * @return
     */
    @PutMapping(value = "/v1/repositories/raw/group/{repositoryName}", produces = "application/json;charset=utf-8")
    ApiResponseXO<Void> updateRawGroupRepository(@PathVariable("repositoryName") String repositoryName, @RequestBody @Valid CreateRawGroupRequest request);

    /**
     * 创建Raw-hosted仓库
     *
     * @param request
     * @return
     */
    @PostMapping(value = "/v1/repositories/raw/hosted", produces = "application/json;charset=utf-8")
    ApiResponseXO<Void> createRawHostedRepository(@RequestBody @Valid CreateRawHostedRequest request);

    /**
     * 创建Raw-proxy仓库
     *
     * @param request
     * @return
     */
    @PostMapping(value = "/v1/repositories/raw/proxy", produces = "application/json;charset=utf-8")
    ApiResponseXO<Void> createRawProxyRepository(@RequestBody @Valid CreateRawProxyRequest request);

}
